<?php
namespace App\Api\Controllers;

use App\Enums\UserEnum;
use Dcat\Admin\Models\Administrator;
use Dingo\Api\Routing\Helpers;
use Illuminate\Routing\Controller;
use Dingo\Api\Http\Request;

class BaseController extends Controller
{
    use Helpers;

    protected $admin_info = [];

    public function __construct(Request $request) {
        if(!config('app.app_start')) {
            echo json_encode([
                'success'       => false,
                'message'       => '系统升级中，请稍后再试',
                'code'          => 500,
                'data'          => []
            ], JSON_UNESCAPED_UNICODE);
            die();
        }

        $admin_id = $request -> get('admin_id');

        if($admin_id) {
            $this->admin_info = Administrator::firstWhere('id',$admin_id) -> toArray();
        }
    }

    protected function success($data = [], $message = "OK", $code = 200)
    {
        return $this->response->array([
            'success'   => true,
            'data'      => $data,
            'message'   => $message,
            'code'      => $code
        ]);
    }

    protected function error($message = "操作失败", $code = -1)
    {
        return $this->response->array([
            'success'   => false,
            'data'      => [],
            'message'   => $message,
            'code'      => $code
        ]);
    }
}
